from django.contrib import admin

from BaiHongAPI.my_admin import myAdminSite
from app.models import User, Material, Supplyer, Processor, WorkShop, ReceiveRecords, RepertoryRecords, PayRecords, \
    BuyRecords, ReturnGoodsRecords


# UserAdmin
@admin.register(User, site=myAdminSite)
class UserAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'username',
        'is_superuser',
        'material_suppplier_info',
        'processor_info',
        'material_info',
        'apartment_info',
        'query_info',
        'repertory_info',
        'process_material_remain',
        'history_workshop_info',
        'cost_info',
        'pay_info',
        'history_info',
        'statistic_info',
        'repertory_bill_info',
        'pay_bill_info',
        'receive_info',
        'buy_process_info',
        'return_info',
    ]

    list_display_links = ['username']
    search_fields = ['username']
    list_filter = ['username', 'material_suppplier_info', 'processor_info']
    save_on_top = True
    save_on_bottom = True


# MaterialAdmin
@admin.register(Material, site=myAdminSite)
class MaterialAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'material_kind_size',
        'supplyer',
        'line_kind_size',
        'number',
        'material_level',
        'comment_one',
        'comment_two',
    ]

    list_display_links = ['material_kind_size']
    search_fields = ['material_kind_size']
    list_filter = ['material_kind_size', 'line_kind_size', 'material_level']
    save_on_top = True
    save_on_bottom = True


# 供应商
@admin.register(Supplyer, site=myAdminSite)
class SupplyerAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'company_name',
        'company_short_name',
        'company_address',
        'company_phone_number',
        'fax',
        'taxpayer_code',
        'num',
        'other_account',
        'account_name',
        'account_bank',
        'linkman',
        'linkman_phone_number',
        'linkman_mobile_number',
        'comment_one',
        'comment_two',

    ]

    list_display_links = ['company_name']
    search_fields = ['company_name']
    list_filter = ['company_name', 'company_phone_number', 'account_bank']
    save_on_top = True
    save_on_bottom = True


# 加工商
@admin.register(Processor, site=myAdminSite)
class ProcessorAdmin(SupplyerAdmin):
    pass


# 车间
@admin.register(WorkShop, site=myAdminSite)
class WorkShopAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'name',
        'status',
    ]

    list_display_links = ['name']
    search_fields = ['name']
    list_filter = ['name', 'status']
    save_on_top = True
    save_on_bottom = True


# 领用记录
@admin.register(ReceiveRecords, site=myAdminSite)
class ReceiveRecordsAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'workshop',
        'supplyer',
        'material',
        'receive_date',
        'class_one_weight',
        'class_two_weight',
        'oil_silk_weight',
        'other_weight',
        'comment_one',
        'comment_two',
    ]

    list_display_links = ['workshop']
    search_fields = ['workshop', 'supplyer', 'material']
    list_filter = ['workshop', 'supplyer', 'receive_date']
    save_on_top = True
    save_on_bottom = True


# 入库记录
@admin.register(RepertoryRecords, site=myAdminSite)
class RepertoryRecordsAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'material',
        'entry_type',
        'department',
        'date',
        'class_one_weight',
        'class_two_weight',
        'oil_silk_weight',
        'other_weight',
        'price',
        'sum_cost',
        'cur_cost',
        'carriage',
        'comment_one',
        'comment_two',
    ]
    list_display_links = ['material']
    search_fields = ['material', 'entry_type', 'department']
    list_filter = ['material', 'entry_type', 'date']
    save_on_top = True
    save_on_bottom = True


# 付款记录
@admin.register(PayRecords, site=myAdminSite)
class PayRecordsAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'payee',
        'account',
        'cost',
        'date',
        'abstract',
        'comment',
    ]

    list_display_links = ['payee']
    search_fields = ['payee', 'account', 'abstract']
    list_filter = ['payee', 'date']
    save_on_top = True
    save_on_bottom = True

#采购记录
@admin.register(BuyRecords,site=myAdminSite)
class BuyRecordsAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'material',
        'date',
        'processor',
        'num',
        'each_weight',
        'buy_weight',
        'price',
        'carriage',
        'sum_cost',
        'real_cost',
        'process_cost_rate',
        'tray_num',
        'comment_one',
        'comment_two',
    ]

    list_display_links = ['material']
    search_fields = ['material', 'supplyer', 'id']
    list_filter = ['material', 'date']
    save_on_top = True
    save_on_bottom = True


#退货记录
@admin.register(ReturnGoodsRecords,site=myAdminSite)
class ReturnGoodsRecordsAdmin(admin.ModelAdmin):
    list_display = [
        'id',
        'material',
        'processor',
        'number',
        'date',
        'reason',
        'comment_one',
        'comment_two',
    ]

    list_display_links = ['material']
    search_fields = ['material', 'id']
    list_filter = ['material', 'date']
    save_on_top = True
    save_on_bottom = True


